// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

func findKthNumber(array []int, k int) int {
	number, index := 1, 0
	for index < len(array) {
		if array[index] != number {
			k--
		} else {
			index++
		}
		if k == 0 {
			break
		}
		number++
	}
	if k != 0 {
		number += k - 1
	}
	return number
}

func main() {
	array := []int{1, 2, 4, 5, 6, 8, 99, 251, 320}
	res := findKthNumber(array, 6)
	fmt.Println(res)
}

//$ go run interview7-1.go
//12
